package com.library.controllers;

import java.io.IOException;
import java.util.Date;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;

import com.library.slayer.model.LMSBook;
import com.library.slayer.service.LMSBookLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ParamUtil;

@Controller(value = "UpdateBookController")
@RequestMapping("VIEW")  
public class UpdateBookController {
	 @RenderMapping(params = "action=update")
     public String update() {
         return "update";
     }

 @ActionMapping(params = "action=updateBook")
 public void updateBook(ActionRequest actionRequest,ActionResponse actionResponse) throws IOException, SystemException, PortalException{
    
     long bookId = ParamUtil.getLong(actionRequest, "bookId");
     String bookTitle = ParamUtil.getString(actionRequest, "bookTitle");
     String author = ParamUtil.getString(actionRequest, "author");
     LMSBook book = null;
    
             if (bookId > 0L) {
                 book = LMSBookLocalServiceUtil.getLMSBook(bookId);
                 book.setBookId(bookId);
                 book.setBookTitle(bookTitle);
                 book.setAuthor(author);
                 book.setCreateDate(new Date());
                 LMSBookLocalServiceUtil.updateLMSBook(book);
                
                 String redirectURL = ParamUtil.getString(actionRequest, "redirectURL");
                 actionResponse.sendRedirect(redirectURL);
        
                
             }
 	}
}
